<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>

<body>
    <div class="layui-container">
        <div class="layui-row">
            <div class="layui-col-lg-offset3" layui-col-lg6>
                <div class="layui-form layuimini-form">
                    <form class="layui-form" action="" lay-filter="vacation">
                    <input type="hidden" name="id" value="" class="layui-input"></input>

                        <div class="layui-form-item">
                            <label class="layui-form-label">职工号</label>
                            <div class="layui-input-block">
                                <input type="text" name="vwnoid" required lay-verify="required" placeholder="请输入职工号"
                                    autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <input type="hidden" name="id" value="" class="layui-input">
                        <div class="layui-form-item">
                            <label class="layui-form-label">职工姓名</label>
                            <div class="layui-input-block">
                                <input type="text" name="vwonname" required lay-verify="required" placeholder="请输入职工姓名"
                                    autocomplete="off" class="layui-input">
                            </div>
                        </div>



                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">请假日期</label></label>
                            <div class="layui-input-block">
                                <input type="text" name="vdate" id="date" lay-verify="date" placeholder="yyyy-MM-dd"
                                    autocomplete="off" class="layui-input">
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <label class="layui-form-label">请假时间</label>
                            <div class="layui-input-block">
                                <input type="text" name="vleavedays" required lay-verify="required" placeholder="请输入请假时间"
                                    autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">请假原因</label>
                            <div class="layui-input-block">
                                <textarea name="vleavecause" class="layui-textarea"placeholder="请输入请假原因"></textarea>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">批准人</label>
                            <div class="layui-input-block">
                                <input type="text" name="vapprover" required lay-verify="required" placeholder="请输入审批人"
                                    autocomplete="off" class="layui-input">
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>
    <script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use('form', function () {
            var form = layui.form,
                $ = layui.jquery,
                laydate = layui.laydate;

            // 日期
            laydate.render({
                elem: '#date'
            });

            var data = JSON.parse(localStorage.getItem("user"));   
            // layer.alert(JSON.stringify(data));
            // 给表单数据赋值
            form.val("vacation", {
                "id": data.id,
                "vwnoid": data.vwnoid,
                "vwonname": data.vwonname,
                "vdate": data.vdate,
                "vleavedays": data.vleavedays,
                "vleavecause": data.vleavecause,
                "vapprover": data.vapprover,
                "right": data.right
            });

            // 监听提交
            form.on('submit(formDemo)', function (data) {
                $.ajax({
                    "url":"http://localhost:8080/vacation/update",
                    "data": data.field,
                    "success":function(result){

                        if(result.code==200){

                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);


                        } else {
                            layer.msg(result.msg);
                        }
                    }
                })
            })

        });
    </script>

</body>
</html>